package com.lagou.homework.modulethree.second;

import java.util.Objects;

/*
 * @className Worker
 * @description: 作业二Worker类型
 * @author admin
 * @date 2022/3/26 13:06
 * */
public class Worker {

    private String name;
    private int age;
    private double salary;

    // 无参构造
    public Worker() {
    }

    // 有参构造
    public Worker(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    // set、get方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        // 如果内存空间地址相等则相同
        if (o == this)
            return true;

        // 如果形参变量o为null或不是同一个类型返回false
        if (o == null || this.getClass() != o.getClass())
            return false;

        // 强制转换类型
        Worker worker = (Worker) o;

        // 判断年龄和工资是否相等
        if (age != worker.age || salary != worker.salary)
            return false;
        // 判断年龄是否相等，相等返回true,否则返回false
        return name != null ? name.equals(worker.name) : worker.name == null;
    }

    @Override
    public int hashCode() {
        int result = age;
        result = age*31+(int)salary+(name!=null?hashCode():0);
        return result;
    }

    public void work(){
        System.out.println(getName()+"正在工作");
    }
}
